{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 第四次练习"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "+ 请务必交到exer4文件夹下，谢绝交到master下\n",
    "+ 请不要改动任何文件，拜托\n",
    "+ 请在10月30日前提交。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "请写一下姓名和学号：\n",
    "+ 姓名  罗丰\n",
    "+ 学号  0154644"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目一\n",
    "一般的歌，分为主歌和副歌部分。副歌有重复，对比两大功能。这就是A－B的基本曲式形式结构。  \n",
    "请找一首你的主打歌，把歌词打印出来，重复的副歌部分，请写一个函数，调用函数打印出来。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "总是梦见云层之上飞过子午线,分不清是黑夜还是白天,带着装不下的期待匆匆的赶来,我再想一遍想一遍\n",
      "我们寻找着在这条路的中间,我们迷失着在这条路的两端,每当黄昏阳光把所有都渲染,你看那金黄多耀眼,我们奔跑着在这条路的中间,我们哭泣着在这条路的两端,每当黄昏阳光把所有都渲染,我看到夜的黑暗\n"
     ]
    }
   ],
   "source": [
    "def verse():\n",
    "    print(\"总是梦见云层之上飞过子午线,分不清是黑夜还是白天,带着装不下的期待匆匆的赶来,我再想一遍想一遍\")\n",
    "def refrain():\n",
    "    print(\"我们寻找着在这条路的中间,我们迷失着在这条路的两端,每当黄昏阳光把所有都渲染,你看那金黄多耀眼,我们奔跑着在这条路的中间,我们哭泣着在这条路的两端,每当黄昏阳光把所有都渲染,我看到夜的黑暗\")\n",
    "verse()\n",
    "refrain()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目二\n",
    "请写一个函数，能够计算均值、样本方差和n(自己写公式哦)。\n",
    "每次输入十个以上的数字，能够输出上述三个统计量。\n",
    "至少调用两次。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "均值是:13.1\n",
      "样本方差是:92.89000000000001\n",
      "均值是:23.9\n",
      "样本方差是:306.4900000000001\n"
     ]
    }
   ],
   "source": [
    "def avevar( *arg):\n",
    "    count=0\n",
    "    sum=0\n",
    "    for value in arg:\n",
    "        count+=1\n",
    "        sum+=value\n",
    "    ave=sum/count\n",
    "    print(\"均值是:%s\" % ave)\n",
    "    sumsquare=0\n",
    "    for value in arg:\n",
    "        sumsquare+=value**2\n",
    "    var=sumsquare/count-ave**2\n",
    "    print(\"样本方差是:%s\" % var)\n",
    "avevar(21,3,5,7,8,6,10,15,36,20)\n",
    "avevar(55,2,23,54,21,3,12,18,19,32)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目三\n",
    "刚才那个函数，默认的是输出均值、样本方差和n，请在后面添加一个关键词参数，让这个函数可以选择输出样本标准差或方差。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "一共有9个数\n",
      "均值是:12.222222222222221\n",
      "0\n",
      "样本方差是:107.44444444444446\n",
      "一共有9个数\n",
      "均值是:20.444444444444443\n",
      "0\n",
      "样本方差是:248.77777777777783\n"
     ]
    }
   ],
   "source": [
    "def avevar(a,*arg):\n",
    "    count=0\n",
    "    sum=0\n",
    "    for value in arg:\n",
    "        count+=1\n",
    "        sum+=value\n",
    "    ave=sum/count\n",
    "    print(\"一共有%s个数\" % count)\n",
    "    print(\"均值是:%s\" % ave)\n",
    "    sumsquare=0\n",
    "    for value in arg:\n",
    "        sumsquare+=value**2\n",
    "    var=sumsquare/count-ave**2\n",
    "    samplevar=var*count/(count-1)\n",
    "    a=int(input())    \n",
    "    if a==0:\n",
    "        print(\"样本方差是:%s\" % samplevar)\n",
    "    else:\n",
    "        varstd=math.sqrt(samplevar)\n",
    "        print(\"样本标准差是：%s\" %varstd )\n",
    "avevar(21,3,5,7,8,6,10,15,36,20)\n",
    "avevar(55,2,23,54,21,3,12,18,19,32)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目四\n",
    "刚才那个函数，请再增加三个关键词参数，让这个参数可以选择输出均值的标准误、最大值、最小值或不输出这三个统计量。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
